/*
 *  PreferencesWindow.h
 *  mediTock
 *
 *  Created by tjmitche on 07/04/2009.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */


#ifndef _PREFERENCESWINDOW_H_
#define _PREFERENCESWINDOW_H_

#include "juce_amalgamated.h"


class PreferencesComponent :	public Component,
								public ButtonListener,
								public FilenameComponentListener,
								public ChangeListener,
								public AudioIODeviceCallback,
								public SliderListener
{
private:
	FilenameComponent* fileChooser;
	TextButton *playButton,*stopButton,*audioSettingsButton;	
	Slider *preMinutesSlider, *preSecondsSlider;
	Slider *hoursSlider, *minutesSlider, *secondsSlider;
	bool slidersChanged;
	
	Label *instructionsLabel, *fileLabel, *preTimerLabel, *timerLabel, *authorLabel;
	
	//to save the chosen file and the timer preferences
	PropertiesFile* propertiesFile;
	
	//Audio Stuff
	// this wraps the actual audio device
	AudioDeviceManager audioDeviceManager;
	// this allows an audio source to be streamed to the IO device
	AudioSourcePlayer audioSourcePlayer;
	// this controls the playback of a positionable audio stream, handling the
	// starting/stopping and sample-rate conversion
	AudioTransportSource transportSource;
	// this source is used to mix together the output from our synth source
	// and wave player source
	MixerAudioSource mixerSource;
	// this is the actual stream that's going to read from the audio file.
	AudioFormatReaderSource* currentAudioFileSource;
	
	File currentFile;
	
	
public:
	PreferencesComponent();
	~PreferencesComponent();
	void buttonClicked (Button* button);
	void changeListenerCallback (void*);
	void filenameComponentChanged (FilenameComponent*);
	void updateButtons(void);
	void resized ();
	void audioDeviceIOCallback (const float** inputChannelData,
								int totalNumInputChannels,
								float** outputChannelData,
								int totalNumOutputChannels,
								int numSamples);
	void audioDeviceAboutToStart (AudioIODevice* device);
	void audioDeviceStopped();
	
	//called by the mainpp
	void startTransport(void);
	void stopTransport(void);
	int getPreTimeInSeconds(void);
	int getTimeInSeconds(void);
	void setTimerInSeconds(int timeSeconds);
	void sliderValueChanged (Slider* slider);
	bool preferencesChanged (void);
	void updateSliderValues();
};

class PreferencesWindow : public DialogWindow,
						  public KeyListener
	{
	private:
		PreferencesComponent* preferencesComponent;
		bool windowVisible;
	public:
		//==============================================================================
		PreferencesWindow();
		~PreferencesWindow();
		
		//==============================================================================
		// called when the close button is pressed or esc is pushed
		void closeButtonPressed();
	
		// It is most likely that your program will be happy thinking of the window's
		// content component as the 'base' level of the application; it can be responsible
		// for storing and maintaining anything considered crucial to the running of the
		// program.
		
		// However, if you want to have anything live above even that, you may
		// want to put it here. You may even wish to step further outside of things and keep
		// some higher management system within the JUCEApplication class that drives the
		// whole shebang, but that's probably not necessary, and can be tricky to maintain!
		
		void startTransport(void);
		void stopTransport(void);
		int getPreTimeInSeconds(void);
		int getTimeInSeconds(void);
		void setTimerInSeconds(int timeSeconds);
		bool preferencesChanged (void);
		void makeVisible (bool setVal);
		bool keyPressed (const KeyPress& key, Component* originatingComponent);
	};




#endif//_PREFERENCESWINDOW_H_ 